﻿using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Applet.RequestDto;
using VisionCloud.Domain.DtoModel.Applet.ResponseDto;
using VisionCloud.Domain.Extension;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Applet;

namespace VisionCloud.Api.Controllers.Applet
{
    /// <summary>
    /// 小程序数据诊断模块
    /// </summary>
    [SystemModule("小程序模块")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/applet/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "小程序模块")]
    public class MeasureDataAnalysisController : ApiBaseController
    {
        public MeasureDataAnalysisService MeasureDataAnalysisService { get; set; }

        /// <summary>
        /// 生成诊断报告
        /// </summary>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<string>))]
        public async Task<ApiResult> WxGetQualityAnalysisReport(WxQualityAnalysisDto query)
        {
            await Contracts.Frequency($"user_WxGetAnalysisReport_limit_{TokenModel.Id}", 1, TimeSpan.FromSeconds(3));
            // 获取质量分析数据
            var result = await MeasureDataAnalysisService.WxGetQualityAnalysisReport(query);
            return result;
        }

        /// <summary>
        /// 获取用户诊断报告
        /// </summary>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<List<WxReportResponse>>))]
        public async Task<ApiResult> WxGetUserReportData(WxReportDto query)
        {
            await Contracts.Frequency($"user_WxGetUserReportData_limit_{OperatorProvider.Get().Id}", 1, TimeSpan.FromSeconds(3));
            // 获取质量分析数据
            var result = await MeasureDataAnalysisService.WxGetUserReportData(query);
            return ApiResult.Success().SetData(result);
        }

        /// <summary>
        /// 获取常见问题列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<List<WxMessageResponseDto>>))]
        public async Task<ApiResult> WxGetCommonMessages(WxMessageDto query)
        {
            // 获取质量分析数据
            var result = await MeasureDataAnalysisService.WxGetCommonMessages(query);
            return result;
        }
    }
}